package com.itcam.lease.web.app.controller.history;


import com.itcam.lease.common.context.LoginUserContext;
import com.itcam.lease.common.login.LoginUserHolder;
import com.itcam.lease.common.result.Result;
import com.itcam.lease.web.app.service.BrowsingHistoryService;
import com.itcam.lease.web.app.vo.history.HistoryItemVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "浏览历史管理")
@RequestMapping("/app/history")
public class BrowsingHistoryController {

    @Autowired
    private BrowsingHistoryService browsingHistoryService;

    /**
     * 分页查询浏览历史记录
     *
     * @param current 当前页码
     * @param size    每页显示的记录数
     * @return 分页查询结果
     */
    @Operation(summary = "获取浏览历史")
    @GetMapping("pageItem")
    private Result<IPage<HistoryItemVo>> page(@RequestParam long current, @RequestParam long size) {
        // 创建分页对象
        Page<HistoryItemVo> page = new Page<>(current, size);
        // 根据用户ID分页查询浏览历史记录
        IPage<HistoryItemVo> result = browsingHistoryService.pageHistoryItemByUserId(page, LoginUserHolder.getLoginUser().getUserId());
        // 返回查询结果
        return Result.ok(result);
    }


}
